import { getAlikeQuestionList, getStandardQuestion } from '@/services/knowledgemanagement';

export default {
  namespace: 'similarQuestion',
  state: {
    total: null,
    loading: false,
    list: [],
  },
  effects: {
    *getQuestionsByQaId({ payload, callback }, { call, put }) {
      const response = yield call(getAlikeQuestionList, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      // const response1 = yield call(getStandardQuestion, payload);
      // yield put({ type: 'save', payload: response1 });
    },
    *getStandardQuestionByQaId({ payload, callback }, { call, put }) {
      const response = yield call(getStandardQuestion, payload);

      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {

      let { list, total } = state;
      if (payload.list !== undefined) {
        list = [payload.list, ...list];
        total = payload.total;
      } else {
        list = [payload, ...list];
      }
      return {
        state,
      };
    },
  },
};
